package com.voicechat.firstmet.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseActivity;
import com.voicechat.firstmet.bean.MySelfInfoBean;
import com.voicechat.firstmet.net.HTTPAPI;
import com.voicechat.firstmet.net.service.MeInfoService;
import com.voicechat.firstmet.utils.ParcelableUtils;
import com.voicechat.firstmet.utils.PhoneUtils;
import com.voicechat.firstmet.utils.SPUtils;
import com.voicechat.firstmet.utils.StatusBarUtils;
import com.voicechat.firstmet.utils.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.activity_imessage
 * @ClassName: ComplainActivity
 * @Description: 投诉页面
 * @Author: ljp
 * @CreateDate: 2018/10/15 15:47
 * @Version: 1.0
 */
public class ComplainActivity extends BaseActivity {

    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.et_complain)
    EditText etComplain;
    @BindView(R.id.tv_submit)
    TextView tvSubmit;
    private String otherId;
    private MySelfInfoBean.ObjectBean mySeleInfo;
    private String token;
    private String id;
    private String deviceInfo;
    @Override
    protected int setStatusBarColor() {
        return 0;
    }

    @Override
    protected boolean isSettingStatusBarText() {
        return false;
    }

    @Override
    protected int loadLayout() {
        return R.layout.activity_complain;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        //透明状态栏
        StatusBarUtils.Full(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        ButterKnife.bind(this);
        mySeleInfo = MySelfInfoBean.ObjectBean.CREATOR.createFromParcel(ParcelableUtils.unmarshall(
                SPUtils.getEditoString(SPUtils.SP_MYSELFINFO)));
        token = SPUtils.getEditoString(SPUtils.SP_TOKEN);
        id = mySeleInfo.getId();
        deviceInfo = PhoneUtils.getDeviceInfo(context);
        initView();

    }

    private void initView() {
        otherId = getIntent().getStringExtra("otherId");
        etComplain.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                String s1 = s.toString().trim();
            }
            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }


    @OnClick({R.id.linear_back, R.id.tv_submit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.linear_back:
                finish();
                break;
            case R.id.tv_submit:
                if(!TextUtils.isEmpty(etComplain.getText().toString().trim()) && etComplain.getText().toString().trim().length() >= 10 ){
                    setHttp();
                }else {
                    toast_MakeText("请输入不少于10个字的投诉内容");
                }
                break;
        }
    }
    /**
     * @method
     * @description 投诉
     * @date: 2018/11/6 19:56
     * @author: ljp
     * @return
     */
    private void setHttp() {
        String content = etComplain.getText().toString().trim();
        MeInfoService.reportAndComplain(mySeleInfo.getId(),token,deviceInfo,content,otherId,"2").subscribe(result -> {
            if(result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETRUN_SUCCESS){
                Intent intent = new Intent(activity,AllSuccessActivity.class);
                intent.putExtra("flag","0");
                startActivity(intent);
                finish();
            }else if(result.getCode() == HTTPAPI.RETURN_CODE_TYPE.RETURN_NO_TOKEN) {
                Utils.setToken(context);
            }else {
                toast_MakeText(result.getMsg());
            }
           // Log.i(TAG, "setHttp: ---------"+result.toString());
        },throwable -> {
          //  Log.i(TAG, "setHttp: ----------"+throwable.toString());
        });

    }

}
